<template>
  <div class="data-permission">
    <el-form :model="dataForm" ref="dataForm" size="small" label-width="20px">
      <el-form-item>
        <el-radio-group v-model="dataForm.dataPermission">
          <el-radio v-for="item in DATA_PERMISSION" :key="item.id" :label="item.id">
            <span class="radio-label">{{item.label}}</span>
            <span>{{item.detatil}}</span>
          </el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { DATA_PERMISSION } from '../js/contant.js'
import { CONSTANT_OBJ } from '@/utils/constant'
import api from '../api'
export default {
  props: { roleData: Object },
  data () {
    return {
      DATA_PERMISSION,
      dataForm: {
        dataPermission: ''
      }
    }
  },
  methods: {
    // 提交
    submit () {
      if (!this.dataForm.dataPermission) {
        this.$message({
          message: `请选择数据权限`,
          type: 'warning'
        })
        return false
      }
      const { roleId, revision } = this.roleData
      api.postChangeDataPermissionsData({ roleId, revision, ...this.dataForm }).then(res => {
        const { responseCode, responseMsg } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          this.$message({
            message: `${responseMsg}`,
            type: 'success'
          })
          this.$emit('uppdataSuccess')
        }
      })
    }
  },
  watch: {
    roleData: {
      handler: function (val) {
        this.dataForm.dataPermission = val.dataPermission
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
.data-permission {
  .radio-label {
    display: inline-block;
    width: 300px;
  }
  .el-radio {
    display: block;
    margin: 20px;
  }
}
</style>
